<template>
  <el-button @click="handleClick" type="primary">
    <slot></slot>
  </el-button>
  <div class="m-choose-icon-dialog-body-height">
    <el-dialog :title="title"  :modelValue="dialogVisible" @close="handleClose" >
    <div class="container-item">
      <div class="item" v-for="(item , index) in Object.keys(ElIcons)" :key="index" @click="clickItem(item)">
        <div class="icon">
          <component  :is='`el-icon-${toLine(item)}`'></component>
        </div>
        <div>{{ item }}</div>
      </div>
    </div>
  </el-dialog>
  </div>
</template>

<script setup lang="ts">
import * as ElIcons from '@element-plus/icons-vue'
import { watch , ref } from 'vue'
import { toLine } from '../../../utils/index'
import { useCopy } from '../../../hooks/useCopy';
let props = defineProps<{
  //弹出框的标题
  title: string,
  //控制弹出框的显示与隐藏
  visible: boolean
}>()
let emits = defineEmits(['update:visible'])
//拷贝一份父组件传递过来的visible
let dialogVisible = ref<boolean>(props.visible)
const handleClick = () => {
  emits('update:visible', !props.visible)
  
}
const handleClose = () => {
  emits('update:visible', !props.visible)
}
watch(() => props.visible, val => {
  dialogVisible.value = val
})
watch(() => dialogVisible.value, val => {
  emits('update:visible', val)
})

//点击图标
const clickItem = (item: string) => {
  let text = `<el-icon-${toLine(item)}/>`
  useCopy(text)
}
</script>

<style lang="scss" scoped>
.container-item{
  display: flex;
  align-items: center;
  justify-content: center;
  justify-content: flex-start;
  flex-wrap: wrap;
}
.item{
  width:25%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
  cursor: pointer;
}
svg{
  width: 2em;
  height: 2em;
}

</style>